import { HttpTransfer } from './transfer/transfer'
import { IOnlineClassService } from './../typing/service/index'
import { IServiceConfig } from './../config'
import { DataManager } from './DataManager'
import { LogService } from './service/LogService'
import { E_LOG_LEVEL } from '../typing/service/ILogService'
import { createServiceURL } from './transfer/urls'
import { ClientService } from './service/ClientService'
import { AuthService } from './service/AuthService'
import { UserService } from './service/UserService'
import { CourseService } from './service/CourseService'
import { MessageService } from './service/MessageService'

export function createService(config: IServiceConfig): IOnlineClassService {
  // const baseUrl = process.env.NODE_ENV === 'development' ? '' : config.serverDomain?.apiDomain || ''
  const baseUrl = ''
  const http = new HttpTransfer(baseUrl)
  const dataManager = DataManager.getInstance()

  const urls = createServiceURL()

  const logger = new LogService(config.logLevel || E_LOG_LEVEL.ALL)
  const client = new ClientService(http, urls.client)
  const auth = new AuthService(http, urls.auth)
  const user = new UserService(http, urls.user)
  const course = new CourseService(http, urls.course)
  const message = new MessageService(http, urls.message)

  const service: IOnlineClassService = {
    http,
    dataManager,
    logger,
    client,
    auth,
    user,
    course,
    message
  }

  return service
}
